<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Skornyakov Anatoliy
 * Date: 15.06.13
 * Time: 22:59
 * 
 */

class Zftest_Plugin_Log extends Zend_Controller_Plugin_Abstract
{
    private $_time = 0;

    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        $this->_time = microtime();
    }

    public function postDispatch(Zend_Controller_Request_Abstract $request)
    {

        //var_dump($request->getServer()); die;
        $strLog = 'IP:' . $request->getServer('REMOTE_ADDR')
            . '; ScriptTime: ' . (microtime() - $this->_time)
            . '; URL:' . $request->getServer('REQUEST_URI')
            . ($request->isPost() ? '; Data-Post:' . Zend_Json::encode($request->getPost()) : '');

        $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');

        if (!$bootstrap->hasResource('Log')) {
            return false;
        }
        $log = $bootstrap->getResource('Log');
        $log->info($strLog);
    }
}